<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>
    // 5 寄生式继承
    function sub(obj) {
      function Cat() { }
      Cat.prototype = obj
      return new Cat()
    }
    function createObj(obj) {
      var tom = sub(obj)
      tom.color = '黑色'
      tom.say = function () {
        console.log('你好')
      }
      return tom
    }
    var animal = {
      name: "动物",
      age: 2
    }
    createObj()
  </script>
</body>

</html>